package com.willcode.demo.orm.hibernate.serviceimpl;

import com.willcode.demo.orm.hibernate.dao.IUserMapper;
import com.willcode.demo.orm.hibernate.entity.User;
import com.willcode.demo.orm.hibernate.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Will
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private IUserMapper userMapper;

    @Override
    public User insert(User user) {
        return userMapper.save(user);
    }

    @Override
    public void deleteById(String id) {
        userMapper.deleteById(id);
    }

    @Override
    public User update(User user) {
        return userMapper.save(user);
    }

    @Override
    public User findById(String id) {
        return userMapper.findById(id).orElse(null);
    }

    @Override
    public List<User> findAll() {
        return (List<User>) userMapper.findAll();
    }

    @Override
    public User find4Link(String id) {
        return userMapper.find4Link(id);
    }
}
